<?php
namespace App\Controllers\Order;
use App\Models\Goods\Goods;
use App\Models\Order\Order;
use App\Models\Goods\GoodsAffiliate;
use App\Models\Store\Store;
use App\Libs\Order\OrderList;

/**
*	获取订单支付信息
*/
class GetPayOrder extends \App\Libs\Base\BaseAction
{
    protected function beforeRun() {
        parent::beforeRun();
        $this->needLogin = TRUE;
    }
	
	public function execute(){
		$user = $this->session->user;
		//获取信息
		$orderSn = $this->request->get('orderSn');//订单号
		//订单信息
		//商品信息
		$order = Order::find( array(
			' order_sn = :osn: and uid = :uid:',
			'bind'=>array( 'osn' => $orderSn , 'uid'=>$user->id)
		) );
		if( empty($order) ){
			return \App\Libs\Views\Json::view(1, '未查找到相关订单信息', Null );
		}
		
		//商品信息
		$goods = Goods::find( array(
			' id = :gid:',
			"columns"=>"goods_name,sale_price,goods_img",
			'bind'=>array( 'gid' => $order->gid )
		) );
		if( empty( $goods ) ){
			return \App\Libs\Views\Json::view(1, '未查找到相关商品信息', Null );
		}else{
			return \App\Libs\Views\Json::view(0, '获取信息成功', ['price'=>Goods::formatPrice($order->price),'goods_name'=>$goods->goods_name, 'goods_img'=>$goods->goods_img ,'stime'=>$order->stime ]) ;
		}
		
		return \App\Libs\Views\Json::view(1, '传递参数有误，请检查参数', Null );
	}
}
